﻿/* 2014/8/3 */
using System.Windows.Forms;

namespace PictureManager.Option
{
    class ExtractionRuleListViewItem : ListViewItem
    {
        private DynamicColumnExtractionRule _rule;

        public ExtractionRuleListViewItem(string pattern, string extractorName)
            : base(new string[] { pattern, extractorName })
        {
            ToolTipText = pattern;

            _rule = new DynamicColumnExtractionRule()
            {
                Pattern = pattern,
                Extractor = extractorName,
                ColumnDefinitions = new DynamicColumnDefinitionInfo[0],
            };
        }

        public ExtractionRuleListViewItem(DynamicColumnExtractionRule rule)
            : base(new string[] { rule.Pattern, rule.Extractor })
        {
            ToolTipText = rule.Pattern;

            _rule = rule;
        }

        public DynamicColumnExtractionRule Rule
        {
            get
            {
                return _rule;
            }
        }

        public string Pattern
        {
            get
            {
                return _rule.Pattern;
            }

            set
            {
                _rule.Pattern = value;
                SubItems[0].Text = value;
                ToolTipText = value;
            }
        }

        public string ExtractorName
        {
            get
            {
                return _rule.Extractor;
            }

            set
            {
                _rule.Extractor = value;
                SubItems[1].Text = value;
            }
        }

        public DynamicColumnDefinitionInfo[] ColumnDefinitions
        {
            get
            {
                return _rule.ColumnDefinitions;
            }

            set
            {
                _rule.ColumnDefinitions = value;
            }
        }
    }
}
